{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import xgboost\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from xgboost import XGBClassifier\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import accuracy_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Querylength</th>\n",
       "      <th>domain_token_count</th>\n",
       "      <th>path_token_count</th>\n",
       "      <th>avgdomaintokenlen</th>\n",
       "      <th>longdomaintokenlen</th>\n",
       "      <th>avgpathtokenlen</th>\n",
       "      <th>tld</th>\n",
       "      <th>charcompvowels</th>\n",
       "      <th>charcompace</th>\n",
       "      <th>ldl_url</th>\n",
       "      <th>...</th>\n",
       "      <th>SymbolCount_FileName</th>\n",
       "      <th>SymbolCount_Extension</th>\n",
       "      <th>SymbolCount_Afterpath</th>\n",
       "      <th>Entropy_URL</th>\n",
       "      <th>Entropy_Domain</th>\n",
       "      <th>Entropy_DirectoryName</th>\n",
       "      <th>Entropy_Filename</th>\n",
       "      <th>Entropy_Extension</th>\n",
       "      <th>Entropy_Afterpath</th>\n",
       "      <th>URL_Type_obf_Type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>12</td>\n",
       "      <td>5.500000</td>\n",
       "      <td>8</td>\n",
       "      <td>4.083334</td>\n",
       "      <td>2</td>\n",
       "      <td>15</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.676804</td>\n",
       "      <td>0.860529</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.00000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>benign</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>12</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>10</td>\n",
       "      <td>3.583333</td>\n",
       "      <td>3</td>\n",
       "      <td>12</td>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.715629</td>\n",
       "      <td>0.776796</td>\n",
       "      <td>0.693127</td>\n",
       "      <td>0.738315</td>\n",
       "      <td>1.00000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>benign</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>11</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>5</td>\n",
       "      <td>4.750000</td>\n",
       "      <td>2</td>\n",
       "      <td>16</td>\n",
       "      <td>11</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0.677701</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.677704</td>\n",
       "      <td>0.916667</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.898227</td>\n",
       "      <td>benign</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>4.500000</td>\n",
       "      <td>7</td>\n",
       "      <td>5.714286</td>\n",
       "      <td>2</td>\n",
       "      <td>15</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.696067</td>\n",
       "      <td>0.879588</td>\n",
       "      <td>0.818007</td>\n",
       "      <td>0.753585</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>benign</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>19</td>\n",
       "      <td>2</td>\n",
       "      <td>10</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>9</td>\n",
       "      <td>2.250000</td>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>0.747202</td>\n",
       "      <td>0.833700</td>\n",
       "      <td>0.655459</td>\n",
       "      <td>0.829535</td>\n",
       "      <td>0.83615</td>\n",
       "      <td>0.823008</td>\n",
       "      <td>benign</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15362</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>13</td>\n",
       "      <td>3.333333</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.797046</td>\n",
       "      <td>0.884870</td>\n",
       "      <td>0.750000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>phishing</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15363</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>9.000000</td>\n",
       "      <td>16</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.797564</td>\n",
       "      <td>0.813569</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.00000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>phishing</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15364</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>6.666666</td>\n",
       "      <td>10</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.791104</td>\n",
       "      <td>0.801139</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>phishing</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15365</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>13</td>\n",
       "      <td>3.333333</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.716580</td>\n",
       "      <td>0.787659</td>\n",
       "      <td>0.871049</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>phishing</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15366</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>9.000000</td>\n",
       "      <td>15</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.797564</td>\n",
       "      <td>0.807835</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.00000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>phishing</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>15367 rows × 80 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       Querylength  domain_token_count  path_token_count  avgdomaintokenlen  \\\n",
       "0                0                   2                12           5.500000   \n",
       "1                0                   3                12           5.000000   \n",
       "2                2                   2                11           4.000000   \n",
       "3                0                   2                 7           4.500000   \n",
       "4               19                   2                10           6.000000   \n",
       "...            ...                 ...               ...                ...   \n",
       "15362            0                   2                 3           8.000000   \n",
       "15363            0                   3                 0           9.000000   \n",
       "15364            0                   3                 2           6.666666   \n",
       "15365            0                   2                 3           8.000000   \n",
       "15366            0                   2                 3           9.000000   \n",
       "\n",
       "       longdomaintokenlen  avgpathtokenlen  tld  charcompvowels  charcompace  \\\n",
       "0                       8         4.083334    2              15            7   \n",
       "1                      10         3.583333    3              12            8   \n",
       "2                       5         4.750000    2              16           11   \n",
       "3                       7         5.714286    2              15           10   \n",
       "4                       9         2.250000    2               9            5   \n",
       "...                   ...              ...  ...             ...          ...   \n",
       "15362                  13         3.333333    2               3            2   \n",
       "15363                  16              NaN    3               0            0   \n",
       "15364                  10         3.000000    3               3            2   \n",
       "15365                  13         3.333333    2               4            2   \n",
       "15366                  15         3.000000    2               2            1   \n",
       "\n",
       "       ldl_url  ...  SymbolCount_FileName  SymbolCount_Extension  \\\n",
       "0            0  ...                    -1                     -1   \n",
       "1            2  ...                     1                      0   \n",
       "2            0  ...                     2                      0   \n",
       "3            0  ...                     0                      0   \n",
       "4            0  ...                     5                      4   \n",
       "...        ...  ...                   ...                    ...   \n",
       "15362        0  ...                     0                      0   \n",
       "15363        0  ...                    -1                     -1   \n",
       "15364        0  ...                     0                      0   \n",
       "15365        0  ...                     0                      0   \n",
       "15366        0  ...                     1                      0   \n",
       "\n",
       "       SymbolCount_Afterpath  Entropy_URL  Entropy_Domain  \\\n",
       "0                         -1     0.676804        0.860529   \n",
       "1                         -1     0.715629        0.776796   \n",
       "2                          1     0.677701        1.000000   \n",
       "3                         -1     0.696067        0.879588   \n",
       "4                          3     0.747202        0.833700   \n",
       "...                      ...          ...             ...   \n",
       "15362                     -1     0.797046        0.884870   \n",
       "15363                     -1     0.797564        0.813569   \n",
       "15364                     -1     0.791104        0.801139   \n",
       "15365                     -1     0.716580        0.787659   \n",
       "15366                     -1     0.797564        0.807835   \n",
       "\n",
       "       Entropy_DirectoryName  Entropy_Filename  Entropy_Extension  \\\n",
       "0                  -1.000000         -1.000000           -1.00000   \n",
       "1                   0.693127          0.738315            1.00000   \n",
       "2                   0.677704          0.916667            0.00000   \n",
       "3                   0.818007          0.753585            0.00000   \n",
       "4                   0.655459          0.829535            0.83615   \n",
       "...                      ...               ...                ...   \n",
       "15362               0.750000          1.000000            0.00000   \n",
       "15363              -1.000000         -1.000000           -1.00000   \n",
       "15364                    NaN          1.000000            0.00000   \n",
       "15365               0.871049          1.000000            0.00000   \n",
       "15366                    NaN          1.000000            1.00000   \n",
       "\n",
       "       Entropy_Afterpath  URL_Type_obf_Type  \n",
       "0              -1.000000             benign  \n",
       "1              -1.000000             benign  \n",
       "2               0.898227             benign  \n",
       "3              -1.000000             benign  \n",
       "4               0.823008             benign  \n",
       "...                  ...                ...  \n",
       "15362          -1.000000           phishing  \n",
       "15363          -1.000000           phishing  \n",
       "15364          -1.000000           phishing  \n",
       "15365          -1.000000           phishing  \n",
       "15366          -1.000000           phishing  \n",
       "\n",
       "[15367 rows x 80 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv('Data/Phishing.csv')\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = data.dropna(axis = 0)\n",
    "y = data.pop('URL_Type_obf_Type')\n",
    "X = data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Querylength</th>\n",
       "      <th>domain_token_count</th>\n",
       "      <th>path_token_count</th>\n",
       "      <th>avgdomaintokenlen</th>\n",
       "      <th>longdomaintokenlen</th>\n",
       "      <th>avgpathtokenlen</th>\n",
       "      <th>tld</th>\n",
       "      <th>charcompvowels</th>\n",
       "      <th>charcompace</th>\n",
       "      <th>ldl_url</th>\n",
       "      <th>...</th>\n",
       "      <th>SymbolCount_Directoryname</th>\n",
       "      <th>SymbolCount_FileName</th>\n",
       "      <th>SymbolCount_Extension</th>\n",
       "      <th>SymbolCount_Afterpath</th>\n",
       "      <th>Entropy_URL</th>\n",
       "      <th>Entropy_Domain</th>\n",
       "      <th>Entropy_DirectoryName</th>\n",
       "      <th>Entropy_Filename</th>\n",
       "      <th>Entropy_Extension</th>\n",
       "      <th>Entropy_Afterpath</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>14624</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>9</td>\n",
       "      <td>4.250000</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.816235</td>\n",
       "      <td>0.916850</td>\n",
       "      <td>0.871049</td>\n",
       "      <td>0.962479</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5113</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>6</td>\n",
       "      <td>4.307692</td>\n",
       "      <td>2</td>\n",
       "      <td>14</td>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.697210</td>\n",
       "      <td>0.929897</td>\n",
       "      <td>0.871049</td>\n",
       "      <td>0.711838</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12356</th>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>3.666667</td>\n",
       "      <td>7</td>\n",
       "      <td>3.400000</td>\n",
       "      <td>3</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0.787853</td>\n",
       "      <td>0.833700</td>\n",
       "      <td>0.842981</td>\n",
       "      <td>0.861719</td>\n",
       "      <td>0.897617</td>\n",
       "      <td>0.894886</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6922</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>7</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>3</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.766840</td>\n",
       "      <td>0.887436</td>\n",
       "      <td>0.890135</td>\n",
       "      <td>0.833333</td>\n",
       "      <td>0.827729</td>\n",
       "      <td>-1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14679</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>9</td>\n",
       "      <td>4.250000</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.793898</td>\n",
       "      <td>0.916850</td>\n",
       "      <td>0.871049</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1848</th>\n",
       "      <td>13</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>4.500000</td>\n",
       "      <td>6</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>2</td>\n",
       "      <td>23</td>\n",
       "      <td>17</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>14</td>\n",
       "      <td>13</td>\n",
       "      <td>12</td>\n",
       "      <td>0.676591</td>\n",
       "      <td>0.796658</td>\n",
       "      <td>0.871049</td>\n",
       "      <td>0.692652</td>\n",
       "      <td>0.699647</td>\n",
       "      <td>0.695870</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8927</th>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>10</td>\n",
       "      <td>6.666666</td>\n",
       "      <td>14</td>\n",
       "      <td>6.500000</td>\n",
       "      <td>3</td>\n",
       "      <td>12</td>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.736373</td>\n",
       "      <td>0.808833</td>\n",
       "      <td>0.757206</td>\n",
       "      <td>0.877406</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3781</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>11</td>\n",
       "      <td>4.500000</td>\n",
       "      <td>7</td>\n",
       "      <td>3.727273</td>\n",
       "      <td>2</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.769878</td>\n",
       "      <td>0.939794</td>\n",
       "      <td>0.780753</td>\n",
       "      <td>0.866875</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2031</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>5.500000</td>\n",
       "      <td>9</td>\n",
       "      <td>4.375000</td>\n",
       "      <td>2</td>\n",
       "      <td>11</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>-1</td>\n",
       "      <td>0.776924</td>\n",
       "      <td>0.860529</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>-1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7983</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>7</td>\n",
       "      <td>7.833334</td>\n",
       "      <td>2</td>\n",
       "      <td>23</td>\n",
       "      <td>36</td>\n",
       "      <td>41</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0.583873</td>\n",
       "      <td>0.789771</td>\n",
       "      <td>0.750290</td>\n",
       "      <td>0.582609</td>\n",
       "      <td>0.570740</td>\n",
       "      <td>0.549769</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5378 rows × 79 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       Querylength  domain_token_count  path_token_count  avgdomaintokenlen  \\\n",
       "14624            0                   2                 4           6.000000   \n",
       "5113             0                   2                13           4.000000   \n",
       "12356            3                   3                 7           3.666667   \n",
       "6922             0                   3                 7           4.000000   \n",
       "14679            0                   2                 4           6.000000   \n",
       "...            ...                 ...               ...                ...   \n",
       "1848            13                   2                13           4.500000   \n",
       "8927             0                   3                10           6.666666   \n",
       "3781             0                   2                11           4.500000   \n",
       "2031             0                   2                 8           5.500000   \n",
       "7983             0                   2                 7           5.000000   \n",
       "\n",
       "       longdomaintokenlen  avgpathtokenlen  tld  charcompvowels  charcompace  \\\n",
       "14624                   9         4.250000    2               2            1   \n",
       "5113                    6         4.307692    2              14            8   \n",
       "12356                   7         3.400000    3               9            6   \n",
       "6922                    7         4.000000    3               5            4   \n",
       "14679                   9         4.250000    2               4            1   \n",
       "...                   ...              ...  ...             ...          ...   \n",
       "1848                    6         3.000000    2              23           17   \n",
       "8927                   14         6.500000    3              12            8   \n",
       "3781                    7         3.727273    2               9            5   \n",
       "2031                    9         4.375000    2              11            8   \n",
       "7983                    7         7.833334    2              23           36   \n",
       "\n",
       "       ldl_url  ...  SymbolCount_Directoryname  SymbolCount_FileName  \\\n",
       "14624        2  ...                          1                     1   \n",
       "5113         1  ...                          1                     1   \n",
       "12356        0  ...                          2                     3   \n",
       "6922         1  ...                          2                     1   \n",
       "14679        1  ...                          1                     1   \n",
       "...        ...  ...                        ...                   ...   \n",
       "1848         0  ...                          1                    14   \n",
       "8927         9  ...                          3                     1   \n",
       "3781         0  ...                          3                     1   \n",
       "2031         0  ...                         -1                    -1   \n",
       "7983        41  ...                          3                     2   \n",
       "\n",
       "       SymbolCount_Extension  SymbolCount_Afterpath  Entropy_URL  \\\n",
       "14624                      0                     -1     0.816235   \n",
       "5113                       0                     -1     0.697210   \n",
       "12356                      2                      1     0.787853   \n",
       "6922                       0                     -1     0.766840   \n",
       "14679                      0                     -1     0.793898   \n",
       "...                      ...                    ...          ...   \n",
       "1848                      13                     12     0.676591   \n",
       "8927                       0                     -1     0.736373   \n",
       "3781                       0                     -1     0.769878   \n",
       "2031                      -1                     -1     0.776924   \n",
       "7983                       1                      0     0.583873   \n",
       "\n",
       "       Entropy_Domain  Entropy_DirectoryName  Entropy_Filename  \\\n",
       "14624        0.916850               0.871049          0.962479   \n",
       "5113         0.929897               0.871049          0.711838   \n",
       "12356        0.833700               0.842981          0.861719   \n",
       "6922         0.887436               0.890135          0.833333   \n",
       "14679        0.916850               0.871049          1.000000   \n",
       "...               ...                    ...               ...   \n",
       "1848         0.796658               0.871049          0.692652   \n",
       "8927         0.808833               0.757206          0.877406   \n",
       "3781         0.939794               0.780753          0.866875   \n",
       "2031         0.860529              -1.000000         -1.000000   \n",
       "7983         0.789771               0.750290          0.582609   \n",
       "\n",
       "       Entropy_Extension  Entropy_Afterpath  \n",
       "14624           1.000000          -1.000000  \n",
       "5113            1.000000          -1.000000  \n",
       "12356           0.897617           0.894886  \n",
       "6922            0.827729          -1.000000  \n",
       "14679           1.000000          -1.000000  \n",
       "...                  ...                ...  \n",
       "1848            0.699647           0.695870  \n",
       "8927            1.000000          -1.000000  \n",
       "3781            1.000000          -1.000000  \n",
       "2031           -1.000000          -1.000000  \n",
       "7983            0.570740           0.549769  \n",
       "\n",
       "[5378 rows x 79 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1234)\n",
    "X_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "E:\\Anaconda\\envs\\ml-networking\\lib\\site-packages\\xgboost\\sklearn.py:1146: UserWarning: The use of label encoder in XGBClassifier is deprecated and will be removed in a future release. To remove this warning, do the following: 1) Pass option use_label_encoder=False when constructing XGBClassifier object; and 2) Encode your labels (y) as integers starting with 0, i.e. 0, 1, 2, ..., [num_class - 1].\n",
      "  warnings.warn(label_encoder_deprecation_msg, UserWarning)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[22:29:07] WARNING: C:/Users/Administrator/workspace/xgboost-win64_release_1.4.0/src/learner.cc:1095: Starting in XGBoost 1.3.0, the default evaluation metric used with the objective 'binary:logistic' was changed from 'error' to 'logloss'. Explicitly set eval_metric if you'd like to restore the old behavior.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,\n",
       "              colsample_bynode=1, colsample_bytree=1, gamma=0, gpu_id=-1,\n",
       "              importance_type='gain', interaction_constraints='',\n",
       "              learning_rate=0.300000012, max_delta_step=0, max_depth=6,\n",
       "              min_child_weight=1, missing=nan, monotone_constraints='()',\n",
       "              n_estimators=100, n_jobs=16, num_parallel_tree=1, random_state=0,\n",
       "              reg_alpha=0, reg_lambda=1, scale_pos_weight=1, subsample=1,\n",
       "              tree_method='exact', validate_parameters=1, verbosity=None)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model = XGBClassifier()\n",
    "model.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_pred = model.predict(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9851301115241635"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "accuracy_score(y_test,y_pred)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "20bebc860e821dfc8c3402aa900049950a23cadb8eca4814f2eb319ccf2768b5"
  },
  "kernelspec": {
   "display_name": "Python 3.8.11 64-bit ('ml-networking': conda)",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.11"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
